package com.yonyou.byb.utils;

import java.util.ArrayList;
import java.util.List;

import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Logger;
import nc.bs.pfxx.ResponseMessage;
import nc.itf.byb.service.ISendDocService;

import org.dom4j.Document;

import com.yonyou.byb.RespMsg;

public class PfxxDealTool {

	public List<RespMsg> dealWithDoc(Document doc){
		List<RespMsg> list = new ArrayList<RespMsg>();

		try {
			
			List<ResponseMessage> msglist = NCLocator.getInstance().lookup(ISendDocService.class).sendDoc(doc);
			for(ResponseMessage msg : msglist){
				RespMsg remsg = new RespMsg();
				if(msg.getResultCode().equals("1")){
					remsg.setBillid(msg.getBdocId());
					remsg.setErrmsg("");
					remsg.setNcid(msg.getContent());
					remsg.setVstatus(RespMsg.SUCCESS);
					list.add(remsg);
				} else {
					remsg.setBillid(msg.getBdocId());
					remsg.setErrmsg(msg.getResultDescription());
					remsg.setNcid(msg.getContent());
					remsg.setVstatus(RespMsg.FAILED);
					list.add(remsg);
				}
			}
		} catch (Exception e) {
			Logger.error(e.getMessage(),e);
			RespMsg remsg = new RespMsg();
			remsg.setErrmsg(e.getMessage());
			remsg.setVstatus(RespMsg.FAILED);
			list.add(remsg);
		}
		return list;
	}
}
